<?xml version="1.0" encoding="UTF-8"?>
<!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:h="http://java.sun.com/jsf/html"
	  xmlns:f="http://java.sun.com/jsf/core"
	  xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
	<title>AIC 11 Services - Rating</title>
	<h:outputStylesheet name="style.css" library="css"/>


</h:head>
<h:body>
	<h:outputScript name="jsf.js" library="javax.faces" target="head"/>


	<div id="container">

		<p:ajaxStatus style="width:56px;height:21px;">
    <f:facet name="start">
		<h:graphicImage value="resources/images/ajax-loader.gif" />
    </f:facet>

    <f:facet name="complete">
        <h:outputText value="" />
    </f:facet>
</p:ajaxStatus>

		<h:form id="offerForm">
			<p:messages id="messages"/>
			<fieldset>
				<legend>
					New offer for customer: <h:outputText value="#{webApp.internalCustomer.lastName} -#{webApp.internalCustomer.firstName}"
													   style="font-weight: bold;"/>
				</legend>
				<h:panelGrid columns="2">
					<h:outputLabel for="resultName" value="Rating:"/>
					<h:outputText id="resultName" value="#{webApp.result}"/>
				</h:panelGrid>

				<p:spacer height="20"/>


				<fieldset>
					<legend>
						Warrantor selection
					</legend>
					<p:dataTable id="customers" value="#{ratingServiceClient.warrantors}" var="war">
						<p:column>
							<f:facet name="header">

							</f:facet>
							<h:selectBooleanCheckbox value="#{webApp.selectionMap[war]}"/>

						</p:column>
						<p:column>
							<f:facet name="header">
								Id
							</f:facet>
							<h:outputText value="#{war.customerId}"/>
						</p:column>
						<p:column>
							<f:facet name="header">
								Name
							</f:facet>
							<h:outputText value="#{war.lastName} ,"/> <h:outputText value="#{war.firstName}"/>
						</p:column>
						<p:column>
							<f:facet name="header">
								City
							</f:facet>
							<h:outputText value="#{war.address.city} - #{war.address.zipCode}"/>
						</p:column>
						<p:column>
							<f:facet name="header">
								Disbursement preference
							</f:facet>
							<h:outputText value="#{war.distbursement}"/>
						</p:column>

					</p:dataTable>
					<h:panelGrid columns="3" id="grid">
						<h:outputLabel for="money" value="Betrag:"/>
						<p:inputText id="money" value="#{webApp.moneyAmount}" required="true"
									 requiredMessage="value needed!">
							<f:validateRegex pattern="[0-9]+" for="money"/>
						</p:inputText>


						<p:message for="money"/>
						<h:outputLabel for="duration" value="Dauer:"/>
						<p:inputText id="duration" value="#{webApp.duration}" required="true"
									 requiredMessage="value needed!">
							<f:validateRegex pattern="[0-9]+" for="duration"/>
						</p:inputText>
						<p:message for="duration"  />
						<h:outputLabel for="comment" value="Kommentar:"/>
						<p:inputTextarea id="comment" value="#{webApp.comment}" required="true"
										 requiredMessage="value needed!"/>
						<p:message for="comment"/>
					</h:panelGrid>

				</fieldset>

				<p:commandButton value="Generate Offer!" actionListener="#{webApp.generateOffer}"
								 update="finalsePanel grid customers" disabled="#{webApp.renderSuccess}"/>

				<p:outputPanel id="finalsePanel">
					<h2>Offer:</h2>
					<h:panelGrid columns="2">
						<h:outputLabel value="Amount:"/>
						<h:outputText value="#{webApp.creditRequest.money.amount}" required="true"
									  requiredMessage="value needed!"/>
						<h:outputLabel value="Duration:"/>
						<h:outputText value="#{webApp.creditRequest.duration.years}" required="true"
									  requiredMessage="value needed!"/>
						<h:outputLabel value="Comment:"/>
						<h:outputText value="#{webApp.creditRequest.reason}" required="true"
									  requiredMessage="value needed!"/>
						<h:outputLabel value="InterestRate:"/>
						<h:outputText value="#{webApp.creditRequest.offer.interestRate.rate}" required="true"
									  requiredMessage="value needed!"/>
						<h:outputLabel value="Warrantor:"/>
						<p:dataList value="#{webApp.creditRequest.warrentors}" var="war" itemType="disc">
							#{war.firstName},#{war.lastName}
						</p:dataList>
					</h:panelGrid>

					<p:commandButton value="Accept" actionListener="#{webApp.acceptOffert}"  update="offerForm:final offerForm:messages offerForm" disabled="#{webApp.renderSuccess}" />

					<p:commandButton value="Decline" action="#{webApp.deleteOffer}" ajax="false"
									 disabled="#{webApp.creditRequest.offer == null or webApp.renderSuccess}}"/>

				</p:outputPanel>
			</fieldset>
			<p:outputPanel id="final">
				<p:outputPanel rendered="#{webApp.renderSuccess}">
					<h1>Offer successfully accepted!</h1>
					<p:commandButton value="Exit" action="#{webApp.exit}" ajax="false" />
				</p:outputPanel>
			</p:outputPanel>
		</h:form>
	</div>
</h:body>
</html>
        